package com.zonta.finance.admin.controller;

import com.zonta.finance.common.dto.ApiResponse;
import com.zonta.finance.domain.form.UpdateEmailAndNameForm;
import com.zonta.finance.domain.form.UpdatePasswordForm;
import com.zonta.finance.domain.form.UpdatePhoneForm;
import com.zonta.finance.domain.vo.CurrentInfoVo;
import com.zonta.finance.serivce.IMemberBindPhoneService;
import com.zonta.finance.serivce.IMemberComService;
import com.zonta.finance.serivce.IMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户模块")
@RestController
@RequestMapping(value = "/user")
@RequiredArgsConstructor
@Slf4j
public class UserController {

    final IMemberComService memberComService;
    final IMemberService memberService;
    final IMemberBindPhoneService memberBindPhoneService;

    @ApiOperation(value = "获取当前登录用户信息")
    @GetMapping(value = "/currentUser")
    public ApiResponse<CurrentInfoVo> currentUser() {
        return ApiResponse.success(memberComService.getCurrentInfo());
    }

    @ApiOperation(value = "修改邮箱和姓名")
    @PostMapping(value = "/updateEmailAndName")
    public ApiResponse<Boolean> updateEmailAndName(@Validated @RequestBody UpdateEmailAndNameForm form) {
        return ApiResponse.success(memberService.updateEmailAndName(form));
    }
    @ApiOperation(value = "修改密码")
    @PostMapping(value = "/updatePassword")
    public ApiResponse<Boolean> updatePassword(@Validated @RequestBody UpdatePasswordForm form) {
        return ApiResponse.success(memberBindPhoneService.updatePassword(form));
    }

    @ApiOperation(value = "修改手机号")
    @PostMapping(value = "/updatePhone")
    public ApiResponse<Boolean> updatePhone(@Validated @RequestBody UpdatePhoneForm form) {
        return ApiResponse.success(memberComService.updatePhone(form));
    }
    @ApiOperation(value = "获取图形验证码")
    @GetMapping(value = "/getBase64Code")
    public ApiResponse<String> getBase64Code() {
        String result = memberComService.getBase64Code();
        return ApiResponse.success(result);
    }
}
